import useUserStore from '../store/user'
import { dateFormat } from '@/common/util'
import { getQuestRewards } from '@/common/api'

async function handleGetQuestRewards() {
  await getQuestRewards(3)
  uni.setStorageSync('orange-music-theatre-get-open-share', dateFormat())
}

const share = {
  // 分享到好友
  async onShareAppMessage() {
    const routes = getCurrentPages() // 获取当前打开过的页面路由数组
    const curRoute = routes[routes.length - 1] // 获取当前页面路由，也就是最后一个打开的页面路由
    const { options, route } = curRoute
    const userStore = useUserStore()
    const id = userStore.userId
    let params = '?pid=' + id
    Object.keys(options).forEach(key => {
      params += `&${key}=${options[key]}`
    })
    const today = dateFormat()
    const history = uni.getStorageSync('orange-music-theatre-get-open-share')
    if (today !== history) {
      await handleGetQuestRewards()
    }
    return {
      path: route + params
    }
  }
  /*  // 分享到朋友圈
  onShareTimeline() {
    return {
      title: '分享标题', // 分享标题
      path: 'pages/index/index?spreaderid=' + uni.getStorageSync('spid'), // 默认为当前页面路径
      imageUrl: '' // 默认为当前页面的截图
    }
  }*/

}
export default share
